package org.codeart.serviceuser.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.codeart.common.dto.PassengerUser;
import org.codeart.serviceuser.mapper.PassengerUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service
public class UserService {

    @Autowired
    private PassengerUserMapper passengerUserMapper;

    public boolean registerUser(String phone) {
        QueryWrapper<PassengerUser> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(PassengerUser::getPassengerPhone, phone);
        PassengerUser user = passengerUserMapper.selectOne(wrapper);
        if (user == null) {
            System.out.println("无记录");
            LocalDateTime now = LocalDateTime.now();
            PassengerUser passengerUser = new PassengerUser();
            passengerUser.setPassengerName("")
                         .setPassengerGender((byte) 0)
                         .setPassengerPhone(phone)
                         .setState((byte) 0)
                         .setGmtCreate(now)
                         .setGmtModified(now);
            int i = passengerUserMapper.insert(passengerUser);
            if (i != -1) {
                return true;
            }
        }
        return true;
    }
    
    public PassengerUser getUserByPhone(String phone) {
        QueryWrapper<PassengerUser> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(PassengerUser::getPassengerPhone, phone);
        return passengerUserMapper.selectOne(wrapper);
    }

}
